import QtQuick 2.15
import QtQuick.Controls 2.15

Window {
    width: 400
    height: 400
    visible: true
    title: "周期定时"

    property int count: 0

    Button {
        text: timer.running ? "停止计时" : "开始计时"
        onClicked: {
            if (timer.running) {
                timer.stop()
            } else {
                count = 0
                timer.start()
            }
        }
    }

    Label {
        anchors.centerIn: parent
        text: "计数: " + count
        font.pixelSize: 24
    }

    Timer {
        id: timer
        interval: 1000 // 1秒
        repeat: true // 设置为周期性触发
        onTriggered: count++
    }
}
